<%@ page language="java" import="java.util.*" contentType="text/html" pageEncoding="UTF-8"%>

<%@ page import="bcnet.service.PriceHistoryService" %>
<%@ page import="bcnet.service.factory.PriceHistoryServiceFactory" %>
<%@ page import="java.text.SimpleDateFormat" %>

<% request.setCharacterEncoding("UTF-8"); 
	//UserService userService = UserServiceFactory.getUserService();
    //User user = userService.getCurrentUser();
    String code = request.getParameter("code");
    String npString = request.getParameter("np");
    String chartWidth = request.getParameter("chartWidth")==null?"100%":request.getParameter("chartWidth");
    String chartHeight = request.getParameter("chartHeight")==null?"400":request.getParameter("chartHeight");
    double np = Double.parseDouble(npString);
    PriceHistoryService priceHistoryService = PriceHistoryServiceFactory.getPriceHistoryService();
	String chartString = priceHistoryService.getPriceChartString(code,np);
%>

<html>
<head>
<title>Bun</title> 
<link type="text/css" rel="stylesheet" href="/stylesheets/main.css" />
    <script type="text/javascript" src="http://www.google.com/jsapi"></script>
    <script type="text/javascript">
      google.load('visualization', '1', {packages: ['corechart']});
    </script>
    <script type="text/javascript">
    function drawVisualization() {
    	 // Create and populate the data table.
    	 var data = new google.visualization.DataTable();
data.addColumn('number', 'Price');
data.addColumn('number', 'Today');
data.addColumn('number', 'Count');
data.addRows([
       	<%=chartString%>
       	]);
    	 
    	 var options = {
    			 title: 'Price',
    	                  curveType: "function",
    	                 width: "<%=chartWidth%>", height: <%=chartHeight%>,
    	               pointSize: 5,
    	                series: {
    	               0: { pointShape: 'circle', pointSize: 10 },
    	               1: { pointShape: 'circle' }
    	              },
    	              vAxis: {gridlines: {color: '#333', count: -1}},
    	              hAxis: {gridlines: {color: '#333', count: -1}, slantedText: true}
    	             
    	               };

    	 // Create and draw the visualization.
    	 new google.visualization.LineChart(document.getElementById('visualization')).
    	     draw(data,options );
    	}
    google.setOnLoadCallback(drawVisualization);
    </script>

<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="pragma" content="no-cache">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no" >
<meta name="HandheldFriendly" content="True">
<META HTTP-EQUIV="Expires" CONTENT="-1">

</head>

  <body style="font-family: Arial;border: 0 none;">
    <div id="visualization" style="width: 100%; height: <%=chartHeight%>px;"></div>
  </body>

</html>
 